// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#include "mk_header.h"
#include "mk_ui_static.h"
#include "mk_engine.h"

namespace MK3DE
{
    CUIStatic::CUIStatic(CUIRenderer* renderer, CUIWindow* parent, D3DXVECTOR2& pos, D3DXVECTOR2& size, const char* name) :
        CUIWindow(renderer, parent, pos, size, name)
    {

    }

    CUIStatic::~CUIStatic()
    {

    }

    BOOL CUIStatic::Render()
    {
        SUIQuad* quad = NULL;
        int index = -1;
        while (_appearence.GetNextQuad(quad, index))
        {
            Rect2D src = quad->rcSrc;
            Rect2D dest = quad->rcDest;
            src.SetOffset(_pos.x, _pos.y);
            dest.SetOffset(_pos.x, _pos.y);
            _renderer->RenderQuad(quad->texture, src, dest, quad->color);
        }

        _renderer->FlushRender();

        _fontRender.Render();

        return CUIWindow::Render();
    }

    void CUIStatic::MakeDefaultAppearence()
    {
        _appearence.Clear();

        _appearence.AddLook();
        SUIQuad quad;
        quad.rcDest.SetRect(0, 0, _size.x, _size.y);

        quad.color.SetColor(UIDAC_PANEL_BG_NORMAL);
        _appearence.AddQuad(quad);

        quad.rcDest.SetRect(0, 0, 1, _size.y);
        quad.color.SetColor(UIDAC_BORDER_LIGHT);
        _appearence.AddQuad(quad);

        quad.rcDest.SetRect(0, 0, _size.x, 1);
        quad.color.SetColor(UIDAC_BORDER_LIGHT);
        _appearence.AddQuad(quad);

        quad.rcDest.SetRect(_size.x, 0, _size.x - 1, _size.y);
        quad.color.SetColor(UIDAC_BORDER_DARK);
        _appearence.AddQuad(quad);

        quad.rcDest.SetRect(0, _size.y - 1, _size.x, _size.y);
        quad.color.SetColor(UIDAC_BORDER_DARK);
        _appearence.AddQuad(quad);
    }

}